//
//  DetailsimaginationSYViewController.m
//  Gxj
//
//  Created by 💋索少杰 on 2017/10/18.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "DetailsimaginationSYViewController.h"
#import "DetailsimaginationSYTableViewCell.h"
#import <SDAutoLayout.h>

@interface DetailsimaginationSYViewController ()<UITableViewDelegate,UITableViewDataSource,UITextViewDelegate,UITextFieldDelegate>
@property(nonatomic, strong) UITableView * tableView;//

@property(nonatomic, strong) UIView * bottonView;
@property(nonatomic, strong) UIButton * dianzanBut;//点赞
@property(nonatomic, strong) UIButton * present;//礼物
@property(nonatomic, strong) UITextView * inputField;//输入栏
@property(nonatomic, strong) UIButton * sendBut;//发送

@property(nonatomic, strong) UILabel * navTitleLbl;
@property(nonatomic, strong) UIView * headView;
//导航条上拉隐藏下拉显示
@property (nonatomic, assign) CGFloat borderNum;
@property (nonatomic ,assign) NSInteger firstComeInNum;
@end

@implementation DetailsimaginationSYViewController
- (void)viewWillAppear:(BOOL)animated {
//    self.navigationController.navigationBar.hidden = NO;
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
//    //去掉导航栏底部的黑线
//    self.navigationController.navigationBar.shadowImage = [UIImage new];
}

- (void)viewWillDisappear:(BOOL)animated {
//    [super viewWillDisappear:animated];
//    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
//    [self.navigationController.navigationBar setShadowImage:nil];
//    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor=[UIColor whiteColor];
    
    //导航条左边按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"fanhui1"] style:UIBarButtonItemStyleDone target:self action:@selector(clickLeftBarButton)];
    //导航条右边按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"xialagenduo"] style:UIBarButtonItemStyleDone target:self action:@selector(clickRightButton)];
    
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]};
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg"]forBarMetrics:UIBarMetricsDefault];
    
    /* 导航标题**/
    // 导航背景视图
    UIView *navBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidthScale(200), kHeightScale(30))];
    self.navigationItem.titleView = navBackView;
    
    UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kWidthScale(200), kHeightScale(30))];
    titleLbl.text = @"会议详情";
    [titleLbl setFont:[UIFont fontWithName:@"Helvetica-Bold" size:17]];
    titleLbl.textColor = [UIColor whiteColor];
    titleLbl.textAlignment = NSTextAlignmentCenter;
    [navBackView addSubview:titleLbl];
    _navTitleLbl = titleLbl;
    
    UIView *backHeadView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidthScale(200), kHeightScale(30))];
    
    UIButton *titleBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, kHeightScale(5), kWidthScale(200), kHeightScale(18))];
    [titleBtn setTitle:@"索大大😁😄" forState:UIControlStateNormal];
    titleBtn.titleLabel.font = [UIFont systemFontOfSize:kWidthScale(15)];
    UIButton *userHead = [[UIButton alloc] initWithFrame:CGRectMake(kWidthScale(30), kHeightScale(6), kWidthScale(18), kHeightScale(18))];
    [userHead setImage:[UIImage imageNamed:@"toixiang"] forState:0];

    [backHeadView addSubview:titleBtn];
    [backHeadView addSubview:userHead];
    [navBackView addSubview:backHeadView];
    _headView = backHeadView;
    // 先让带图片的导航视图隐藏
    _headView.alpha = 0;
    
    _borderNum = 15.f;
    _firstComeInNum = 0;

    //表格设置
    [self.view addSubview:self.tableView];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;// 去掉所有cell的分割线
    
    //控制器底部控件
    [self setButtonViewUp];
}
//导航条返回按钮响应
- (void)clickLeftBarButton
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)clickRightButton
{
    
}

//返回每个分区下的单元格个数，必须实现
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return kHeightScale(877);
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * str= @"biao";
    DetailsimaginationSYTableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:str];
    if (!cell) {
        
        cell=[[DetailsimaginationSYTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }
    cell.selectionStyle=UITableViewStylePlain;
    //cell.backgroundColor=[UIColor orangeColor];
    return cell;
}



- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kHeightScale(0), UIScreenWidth, UIScreenHeight) style:UITableViewStylePlain];
        
        _tableView.delegate = self;
        
        _tableView.dataSource = self;
    }
    return _tableView;
}

//控制器底部控件
- (void)setButtonViewUp
{
    //底部View
    _bottonView=[[UIView alloc] init];
    _bottonView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:_bottonView];
    //位置
    _bottonView.sd_layout
    .bottomSpaceToView(self.view, 0)
    .leftSpaceToView(self.view, 0)
    .rightSpaceToView(self.view, 0)
    .heightIs(kHeightScale(44));
    //点赞
    _dianzanBut=[[UIButton alloc] init];
    [_dianzanBut setImage:[UIImage imageNamed:@"cxdianzanb"] forState:UIControlStateNormal];
    [self.bottonView addSubview:_dianzanBut];
    //位置
    _dianzanBut.sd_layout
    .topSpaceToView(self.bottonView, kHeightScale(26/2))
    .leftSpaceToView(self.bottonView, kWidthScale(15))
    .widthIs(kWidthScale(36/2))
    .heightIs(kHeightScale(35/2));
    //礼物
    _present=[[UIButton alloc] init];
    [_present setImage:[UIImage imageNamed:@"cxliwu"] forState:UIControlStateNormal];
    [self.bottonView addSubview:_present];
    //位置
    _present.sd_layout
    .topSpaceToView(self.bottonView, kHeightScale(26/2))
    .leftSpaceToView(self.dianzanBut, kWidthScale(15))
    .widthIs(kWidthScale(36/2))
    .heightIs(kHeightScale(36/2));
    //输入栏
    _inputField=[[UITextView alloc] init];
    _inputField.layer.borderWidth = 1;
    _inputField.layer.borderColor = [UIColor colorWithRed:(63.0/255) green:(130.0/255) blue:(252.0/255) alpha:1].CGColor;
    _inputField.layer.masksToBounds = YES;
    _inputField.layer.cornerRadius = kWidthScale(10);
    _inputField.textContainerInset = UIEdgeInsetsMake( kHeightScale(5), kWidthScale(15), 30, 30);
    _inputField.text = @"请输入您想说的话";
    _inputField.textAlignment=NSTextAlignmentCenter;
    _inputField.tag = 11111111;
    _inputField.textColor = [UIColor lightGrayColor];
    _inputField.font = [UIFont systemFontOfSize:kWidthScale(15)];
    _inputField.delegate = self;
    [self.bottonView addSubview:_inputField];
    //位置
    _inputField.sd_layout
    .topSpaceToView(self.bottonView, kHeightScale(14/2))
    .leftSpaceToView(self.present, kWidthScale(10))
    .widthIs(kWidthScale(488/2))
    .heightIs(kHeightScale(60/2));
    
    //发送
    _sendBut=[[UIButton alloc] init];
    [_sendBut setImage:[UIImage imageNamed:@"fabu111"] forState:UIControlStateNormal];
    [self.bottonView addSubview:_sendBut];
    //位置
    _sendBut.sd_layout
    .topSpaceToView(self.bottonView, kHeightScale(24/2))
    .leftSpaceToView(self.inputField, kWidthScale(29/2))
    .widthIs(kWidthScale(48/2))
    .heightIs(kHeightScale(40/2));

}

#pragma mark -导航条设置
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    _firstComeInNum ++;
    NSLog(@"%ld",(long)_firstComeInNum);
    if (_firstComeInNum >2) {
        // 表格 y 的滑动位置
        CGFloat contentOffset = scrollView.contentOffset.y +64;
        //NSLog(@"contentOffset :%lf",contentOffset);
        if (contentOffset <0.f) { // y的位置小于0 ，不进行下面的操作 直接退出该方法
            return;
        } else if (contentOffset <_borderNum) { // y 小于 64 ，则显示 titleLbl ，并根据y的大小来改变titleLbl的透明度
            _navTitleLbl.alpha = (_borderNum - contentOffset )/ _borderNum;
            _headView.alpha = 0.f;
        } else if (contentOffset >_borderNum) {
            _navTitleLbl.alpha = 0.f;
            _headView.alpha = (contentOffset -_borderNum )/_borderNum;
        } else if (contentOffset == _borderNum) {
            _navTitleLbl.alpha = 0.f;
            _headView.alpha = 0.f;
        }
        //NSLog(@"%lf",contentOffset);
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
